package com.itheima.controller;

import com.itheima.common.dto.UserOrderDto;
import com.itheima.common.entity.Result;
import com.itheima.common.vo.OrderVo;
import com.itheima.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("user")
@RequestMapping("/order")
@Api(tags = "用户预约管理")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 根据预约id查询预约信息
     * @param id
     * @return
     */
    @GetMapping("/findById")
    @ApiOperation("根据预约id查询预约信息")
    public Result findById(@RequestParam("id") Integer id) {
        log.info("根据预约id查询预约信息：{}", id);
        List<OrderVo> orders = orderService.findById(id);
        return new Result(true, "查询预约信息成功", orders);
    }

    /**
     * 用户预约
     * @param orderDto
     * @return
     */
    @PostMapping("submitOrder")
    @ApiOperation("用户预约")
    public Result submitOrder(@RequestBody UserOrderDto orderDto) {
        log.info("用户预约：{}", orderDto);
        orderService.submitOrder(orderDto);
        return new Result(true, "预约成功");
    }

}
